import time

#Первый файл

f = open('m1_sorted.txt','r')
a =[]
N = 5000
for i in range (5000):
    a.append(int(f.readline()))
t1 = time.time()
for i in range(N-1):
    fl = 0
    for j in range(N - i -1):
        if a[j]> a[j+1]:
            a[j], a[j+1] = a[j+1], a[j]
            fl = 1
    if fl == 0:
        break
t2 = time.time()

print('m1_sorted', round((t2-t1) * 1000), 'milliseconds')
f.close

#Второй файл

f2 = open('m2_reverse.txt','r')
b =[]
H = 5000
for i in range (5000):
    b.append(int(f2.readline()))
t3 = time.time()
for i in range(H-1):
    fl = 0
    for j in range(H - i -1):
        if b[j]> b[j+1]:
            b[j], b[j+1] = b[j+1], b[j]
            fl = 1
    if fl == 0:
        break
t4 = time.time()

print('m2_reverse', int((t4-t3) * 1000), 'milliseconds')
f2.close

#Третий файл

f3 = open('m3_shuffle.txt','r')
c =[]
M = 5000
for i in range (5000):
    c.append(int(f3.readline()))
t5 = time.time()
for i in range(M-1):
    fl = 0
    for j in range(M - i -1):
        if c[j]> c[j+1]:
            c[j], c[j+1] = c[j+1], c[j]
            fl = 1
    if fl == 0:
        break
t6 = time.time()
print('m3_shuffle', int((t6-t5) * 1000), 'milliseconds')
f3.close
